﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>BlockInput - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The BlockInput function disables or enables the user's ability to interact with the computer via keyboard and mouse." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>BlockInput</h1>

<p>Disables or enables the user's ability to interact with the computer via keyboard and mouse.</p>

<pre class="Syntax"><span class="func">BlockInput</span> OnOff
<span class="func">BlockInput</span> SendMouse
<span class="func">BlockInput</span> MouseMove</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>OnOff</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
    <p>This mode blocks all user inputs unconditionally. Specify 下列值之一:</p>
    <p><strong>On</strong> or 1 (<a href="../Variables.htm#True">true</a>): The user is prevented from interacting with the computer (mouse and keyboard input has no effect).</p>
    <p><strong>Off</strong> or 0 (<a href="../Variables.htm#False">false</a>): Input is re-enabled.</p>
  </dd>
  <dt>SendMouse</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>This mode only blocks user inputs while specific send and/or mouse functions are in progress. Specify one of the following words:</p>
    <p><strong>Send</strong>: The user's keyboard and mouse input is ignored while a <a href="Send.htm">SendEvent</a> is in progress (including <a href="Send.htm">Send</a> and <a href="Send.htm">SendText</a> if <code>SendMode "Event"</code> has been used). This prevents the user's keystrokes from disrupting the flow of simulated keystrokes. When the Send finishes, input is re-enabled (unless still blocked by a previous use of <code>BlockInput "On"</code>).</p>
    <p><strong>Mouse</strong>: The user's keyboard and mouse input is ignored while a <a href="Click.htm">Click</a>, <a href="MouseMove.htm">MouseMove</a>, <a href="MouseClick.htm">MouseClick</a>, or <a href="MouseClickDrag.htm">MouseClickDrag</a> is in progress (the traditional <a href="SendMode.htm">SendEvent mode</a> only). This prevents the user's mouse movements and clicks from disrupting the simulated mouse events. When the mouse action finishes, input is re-enabled (unless still blocked by a previous use of <code>BlockInput "On"</code>).</p>
    <p><strong>SendAndMouse</strong>: A combination of the above two modes.</p>
    <p><strong>Default</strong>: Turns off both the <em>Send</em> and the <em>Mouse</em> modes, but does not change the current state of input blocking. For example, if <code>BlockInput "On"</code> is currently in effect, using <code>BlockInput "Default"</code> will not turn it off.</p>
  </dd>
  <dt id="MouseMove">MouseMove</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>This mode only blocks the mouse cursor movement. Specify one of the following words:</p>
    <p><strong>MouseMove</strong>: The mouse cursor will not move in response to the user's physical movement of the mouse (DirectInput applications are a possible exception). When a script first uses this function, the <a href="_InstallMouseHook.htm">mouse hook</a> is installed (if it is not already). The mouse hook will stay installed until the next use of the <a href="Suspend.htm">Suspend</a> or <a href="Hotkey.htm">Hotkey</a> function, at which time it is removed if not required by any hotkeys or hotstrings (see <a href="_Hotstring.htm">#Hotstring NoMouse</a>).</p>
    <p><strong>MouseMoveOff</strong>: Allows the user to move the mouse cursor.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>All three BlockInput modes (<em>OnOff</em>, <em>SendMouse</em> and <em>MouseMove</em>) operate independently of each other. For example, <code>BlockInput "On"</code> will continue to block input until <code>BlockInput "Off"</code> is used, even if one of the words from <em>SendMouse</em> is also in effect. Another example is, if <code>BlockInput "On"</code> and <code>BlockInput "MouseMove"</code> are both in effect, mouse movement will be blocked until both are turned off.</p>
<p class="note"><strong>Note:</strong> The <em>OnOff</em> and <em>SendMouse</em> modes might have no effect if UAC is enabled or the script has not been run as administrator. For more information, refer to the <a href="../FAQ.htm#uac">FAQ</a>.</p>
<p>In preference to BlockInput, it is often better to use <code><a href="SendMode.htm">SendMode</a> "Input"</code> or <code><a href="SendMode.htm">SendMode</a> "Play"</code> so that keystrokes and mouse clicks become uninterruptible. This is because unlike BlockInput, those modes do not discard what the user types during the send; instead, those keystrokes are buffered and sent afterward. Avoiding BlockInput also avoids the need to work around sticking keys as described in the next paragraph.</p>
<p>If BlockInput becomes active while the user is holding down keys, it might cause those keys to become &quot;stuck down&quot;. This can be avoided by waiting for the keys to be released prior to turning BlockInput on, as in this example:</p>
<pre>^!p::
KeyWait "Control"  <em>; Wait for the key to be released.  Use one KeyWait for each of the hotkey's modifiers.</em>
KeyWait "Alt"
BlockInput True
<em>; ... send keystrokes and mouse clicks ...</em>
BlockInput False
return</pre>
<p>Input blocking is automatically and momentarily disabled whenever an <kbd>Alt</kbd> event is sent (then re-enabled afterward).</p>
<p>When BlockInput is in effect, user input is blocked but AutoHotkey can simulate keystrokes and mouse clicks. However, pressing <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Del</kbd> will re-enable input due to a Windows API feature.</p>
<p>Certain types of <a href="_UseHook.htm">hook hotkeys</a> can still be triggered when BlockInput is on. Examples include <code>MButton</code> (mouse hook) and <code>LWin &amp; Space</code> (keyboard hook with explicit prefix rather than modifiers &quot;$#&quot;).</p>
<p>Input is automatically re-enabled when the script closes.</p>
<h2 id="Related">相关</h2>
<p><a href="SendMode.htm">SendMode</a>, <a href="Send.htm">Send</a>, <a href="Click.htm">Click</a>, <a href="MouseMove.htm">MouseMove</a>, <a href="MouseClick.htm">MouseClick</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>BlockInput true
Run "notepad"
WinWaitActive "ahk_class Notepad"
Send "{F5}" <em>; pastes time and date</em>
BlockInput false</pre>
</div>
</body>
</html>